package com.ittx.dzt.meione.service;

import com.ittx.dzt.edi.dto.PlatformApiParamDTO;
import com.ittx.dzt.edi.dto.ShipmentDispatchDTO;
import com.ittx.dzt.edi.dto.StoreConfigDTO;
import com.ittx.dzt.meione.handler.AbstractBaseMeioneApiHandler;
import com.ittx.dzt.sys.response.Result;
import open.constant.PlatformApiConstant;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * 回传订单物流信息
 * <p>
 * cy.shipment.dispatch
 * /erp/un/sys/logistics/callback 回传订单物流信息
 * </p>
 *
 * @author wushixiong
 * @since 2022/5/6 18:12
 */
@Service
public class MeioneShipmentDispatchService extends AbstractBaseMeioneApiHandler<ShipmentDispatchDTO> {

	@Override
	public String getMeioneMethod() {
		return "/erp/un/sys/logistics/callback";
	}

	@Override
	public String getLocalApiMethod() {
		return PlatformApiConstant.InboundInterface.SHIPMENT_DISPATCH;
	}

	@Override
	public Result doProcess(PlatformApiParamDTO platformApiParamDTO, ShipmentDispatchDTO shipmentDispatchDTO) {
		StoreConfigDTO storeConfig = platformApiParamDTO.getStoreConfig();
		Map<String, Object> params = new HashMap<>();
		// detailsNo	String	T	202309150001461281,23083070000962	子订单编号（若有多个逗号隔开）
		// deliveryComCode	String	T	zhongtong	物流公司编码
		// logisticsNo	String	T	SF1351869913475	物流单号
		params.put("businessCode", storeConfig.getStoreUniqueCode());
		params.put("detailsNo", shipmentDispatchDTO.getSourceOrderCode());
		params.put("deliveryComCode", shipmentDispatchDTO.getCarrierCode());
		params.put("logisticsNo", shipmentDispatchDTO.getWaybillCode());
		return this.executeApi(platformApiParamDTO.getStoreConfig(), params, platformApiParamDTO.getRequestId());
	}

}
